package cn.hl.hm.constants;

/**
 * 文件后缀枚举
 * Created by xianghan on 18/1/10.
 */
public enum FileSuffixType {

    EXCEL("excel",new String[]{"xls","xlsx","csv"}),
    SINGLEPIC("singlePic",new String[]{"jpg","jpeg","bmp","gif","png","txt"})
    ;
    /** 文件类型 **/
    private String type;
    /** 文件后缀名 **/
    private String[] suffixs;

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String[] getSuffixs() {
        return suffixs;
    }

    public void setSuffixs(String[] suffixs) {
        this.suffixs = suffixs;
    }

    FileSuffixType(String type, String[] suffixs) {
        this.type = type;
        this.suffixs = suffixs;
    }

    public static FileSuffixType getFileType(String type){
        if (type==null || type.length()==0) {
            return null;
        }
        for (FileSuffixType ft : values()) {
            if (ft.type.equals(type)) {
                return ft;
            }
        }
        return null;
    }

    public boolean contains(String type, String suffix){
        if (suffix!=null&&suffix.length()>0) {
            FileSuffixType fileType=getFileType(type);
            if (fileType!=null) {
                for (String s : fileType.getSuffixs()) {
                    //小写后对比
                    if(s.equals(suffix.toLowerCase())){
                        return true;
                    }
                }
            }
        }
        return false;
    }
}
